package com.sanjiahantang.uilibrary.views.zoomimage;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.sanjiahantang.uilibrary.R;
import com.sanjiahantang.uilibrary.utils.ImageUtils;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by TangZH on 2017/5/2.
 */
public class PicViewPagerAdapter extends PagerAdapter {

    private List<String> mImgPaths;
    private Context mContext;

    public void setmDirPath(String mDirPath) {
        this.mDirPath = mDirPath;
    }

    private String mDirPath;
    private View.OnClickListener mOnClickListener;

    public void setOnClickListener(View.OnClickListener mOnClickListener) {
        this.mOnClickListener = mOnClickListener;
    }

    public PicViewPagerAdapter(Context context, String url) {
        mContext = context;
        mDirPath = url;
    }

    @Override
    public int getCount() {
        return 1;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        final MyImageView imageView = new MyImageView(mContext);
        imageView.setMinimumWidth(10000);
        imageView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
//        String filePath=mDirPath+"/"+mImgPaths.get(position);
//        Bitmap bitmap;
//        bitmap= ImagesTool.decodeSampledBitmapFromPath(filePath,imageView);
//        imageView.setImageBitmap(bitmap);
        Picasso.with(mContext).load(mDirPath).placeholder(R.drawable.i_rect_bg).into(imageView);
        container.addView(imageView);
        imageView.setOnClickListener(mOnClickListener);
        return imageView;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
}
